<template>
  <div class="commentItem">
    <div class="top">
      <div class="left">
        <span>{{obj.user.nickname}}</span> &nbsp;&nbsp;&nbsp;
        <span>2分钟前</span>
      </div>
      <span @click="replyFn(obj.id)">回复</span>
    </div>
    <div class="bottom">{{obj.content}}</div>
    <CommentItem v-if="obj.parent"
                 @reply="replyFn"
                 :obj='obj.parent' />
  </div>
</template>

<script>
export default {
  name: 'CommentItem', //添加了name属性，就相当于注册了自身这个组件了
  props: {
    obj: {
      type: Object,
      required: true,
    },
  },
  methods: {
    replyFn(id) {
      this.$emit('reply', id)
    },
  },
}
</script>

<style lang="less" scoped>
.commentItem {
  border: 1px solid #ccc;
  padding: 5px;
  margin-top: 10px;
  .top {
    font-size: 12px;
    color: #aaa;
    display: flex;
    justify-content: space-between;
  }
  .bottom {
    font-size: 13px;
    line-height: 40px;
  }
}
</style>